package com.example.anew.journey.mynewjourney.firstchangelogic.personalInformation.model;

import android.content.Context;
import android.content.SharedPreferences;

import com.example.anew.journey.mynewjourney.bean.TakeDateBean;
import com.example.anew.journey.mynewjourney.firstchangelogic.personalInformation.bean.InitInformationDateBean;
import com.example.anew.journey.mynewjourney.firstchangelogic.personalInformation.bean.PersonalInformationBean;

import java.text.SimpleDateFormat;
import java.util.Date;

import static android.content.Context.MODE_PRIVATE;



/**
 * 杭州惟君医疗科技有限公司18
 * Created by 20433 on 2018/3/15
 */

public class FirstChangePersonalInformationModel implements ISFirstChangePersonalInformationModel {
    // 存储头像信息
    @Override
    public void storeAvatarInformation(String url,Context mContext) {
        SharedPreferences sharedPreferences = mContext.getSharedPreferences("My_App_Cardiac", MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("my_use_logo", url);
        editor.commit();
    }
    // 存储昵称
    @Override
    public void storeNickname(String niName,Context mContext) {
        SharedPreferences sharedPreferences = mContext.getSharedPreferences("My_App_Cardiac", MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("my_use_name", niName);
        editor.commit();
    }
    // 存储生日
    @Override
    public void StoreBirthday(String birthday,Context mContext) {
        SharedPreferences sharedPreferences = mContext.getSharedPreferences("My_App_Cardiac", MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("my_use_birthday", birthday);
        editor.commit();
    }
    //存数据
    @Override
    public void saveDate(InitInformationDateBean.DataBean bean,Context mContext) {
        SharedPreferences sharedPreferences = mContext.getSharedPreferences("My_App_Cardiac", MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("my_use_id", bean.id);
        editor.putString("my_use_name", bean.cus_name);
        editor.putString("my_use_tel", bean.tel);
        editor.putString("my_use_logo", bean.cus_logo);
        editor.putString("my_use_birthday", bean.birthday);
        editor.putString("my_use_qq", bean.qq);
        editor.putString("my_use_weixin", bean.weixin);
        editor.putString("my_use_token", bean.token);
        editor.putInt("my_stored_data_number",2);
        editor.commit();

    }
    //取出use_id 和token
    @Override
    public TakeDateBean TakeDate(Context mContext) {
        SharedPreferences sharedPreferences = mContext.getSharedPreferences("My_App_Cardiac", MODE_PRIVATE);
        String my_use_id = sharedPreferences.getString("my_use_id", "");
        String my_use_token = sharedPreferences.getString("my_use_token", "");
        TakeDateBean takeDateBean =  new TakeDateBean();
        takeDateBean.setUser_id(my_use_id);
        takeDateBean.setToken(my_use_token);
        return takeDateBean;

    }

    @Override
    public PersonalInformationBean TakePersonalInformation(Context mContext) {
        SimpleDateFormat time = new SimpleDateFormat("yyyy年MM月dd日");
        PersonalInformationBean personalInformationBean =   new PersonalInformationBean();
        SharedPreferences sharedPreferences = mContext.getSharedPreferences("My_App_Cardiac", MODE_PRIVATE);
        String my_use_name = sharedPreferences.getString("my_use_name", "");
        String my_use_logo = sharedPreferences.getString("my_use_logo", "");
        String my_use_birthday = sharedPreferences.getString("my_use_birthday", time.format(new Date()));
      //  NLogger.e("TAG","=======PersonalInformationBean=========="+my_use_birthday);
        personalInformationBean.setUrl(my_use_logo);
        personalInformationBean.setNickname(my_use_name);
        personalInformationBean.setDate(my_use_birthday);
        return personalInformationBean;
    }
}
